{# most, if not all javascripts should go here
   this template is included at the very bottow of the
   main template "base.html"
#}
<div id="no-javascript">
    <noscript class="noscript">
        {% trans app_name = settings.APP_SHORT_NAME %}Please note: {{app_name}} requires javascript to work properly, please enable javascript in your browser, <a href="{{noscript_url}}">here is how</a>{% endtrans %}
    </noscript>
    <script type="text/javascript">
        //IE fix to hide the red margin
        var noscript = document.getElementsByTagName('noscript')[0];
        noscript.style.padding = '0px';
        noscript.style.backgroundColor = 'transparent';
    </script>
</div>
{# this section cannot be compressed because lots of data is runtime #}
<script type="text/javascript">
    askbot['urls']['mark_read_message'] = '{% url "read_message" %}';
    askbot['urls']['get_tags_by_wildcard'] = '{% url "get_tags_by_wildcard" %}';
    askbot['urls']['get_tag_list'] = '{% url "get_tag_list" %}';
    askbot['urls']['follow_user'] = '/followit/follow/user/{{'{{'}}userId{{'}}'}}/';
    askbot['urls']['unfollow_user'] = '/followit/unfollow/user/{{'{{'}}userId{{'}}'}}/';
    askbot['urls']['user_signin'] = '{{ settings.LOGIN_URL }}';
    askbot['urls']['getEditor'] = '{% url "get_editor" %}';
    askbot['urls']['apiGetQuestions'] = '{% url "api_get_questions" %}';
    askbot['urls']['ask'] = '{% url "ask" %}';
	askbot['urls']['questions'] = '{% url "questions" %}';
    askbot['settings']['groupsEnabled'] = {{ settings.GROUPS_ENABLED|as_js_bool }};
    askbot['settings']['static_url'] = '{{ settings.STATIC_URL }}';
    askbot['settings']['minSearchWordLength'] = {{ min_search_word_length }};
    askbot['settings']['mathjaxEnabled'] = {{ settings.ENABLE_MATHJAX|as_js_bool }};
    askbot['settings']['sharingSuffixText'] = '{{ settings.SHARING_SUFFIX_TEXT|escape }}';
    askbot['data']['maxCommentLength'] = {{ settings.MAX_COMMENT_LENGTH }};
    askbot['settings']['editorType'] = '{{ settings.EDITOR_TYPE }}';
    askbot['settings']['commentsEditorType'] = '{{ settings.COMMENTS_EDITOR_TYPE }}';
    askbot['messages']['askYourQuestion'] = '{{ settings.WORDS_ASK_YOUR_QUESTION }}';
    askbot['messages']['questionSingular'] = '{{ settings.WORDS_QUESTION_SINGULAR|escapejs }}';
    askbot['messages']['answerSingular'] = '{{ settings.WORDS_ANSWER_SINGULAR|escapejs }}';
    askbot['messages']['acceptOwnAnswer'] = '{{ settings.WORDS_ACCEPT_OR_UNACCEPT_OWN_ANSWER|escapejs }}';
    askbot['messages']['followQuestions'] = '{{ settings.WORDS_FOLLOW_QUESTIONS|escapejs }}';
    {% if settings.ALLOWED_UPLOAD_FILE_TYPES %}
        askbot['settings']['allowedUploadFileTypes'] = [
            "{{ settings.ALLOWED_UPLOAD_FILE_TYPES|join('", "')|replace('.','') }}"
        ];
    {% else %}
        askbot['settings']['allowedUploadFileTypes'] = [];
    {% endif %}
    askbot['data']['haveFlashNotifications'] = {{ user_messages|as_js_bool }};
    askbot['data']['activeTab'] = '{{ active_tab }}';
    askbot['settings']['csrfCookieName'] = '{{ settings.CSRF_COOKIE_NAME }}';
    {% if search_state %}
        askbot['data']['searchUrl'] = '{{ search_state.query_string()|escapejs }}';
    {% else %}
        askbot['data']['searchUrl'] = '';
    {% endif %}
</script>
{# everything below until the custom js and google analytics is compressable #}
{% compress js %}
<!--<script type="text/javascript" src="{{"/js/jquery-1.7.2.min.js"|media}}"></script>-->
<script type="text/javascript" src='{{"/bootstrap/js/bootstrap.js"|media}}'></script>
<!-- History.js --> 
<script type='text/javascript' src="{{"/js/jquery.history.js"|media }}"></script>
<script type='text/javascript' src="{{"/js/utils.js"|media }}"></script>
<script type="text/javascript" src="{{'/js/live_search.js'|media}}"></script>
{% endcompress %}
<script type="text/javascript">
    /*<![CDATA[*/
    $('.mceStatusbar').remove();//a hack to remove the tinyMCE status bar
    $(document).ready(function(){
        // focus input on the search bar endcomment
        var activeTab = askbot['data']['activeTab'];
        if (inArray(activeTab, ['users', 'questions', 'tags', 'badges'])) {
            var searchInput = $('#keywords');
        } else if (activeTab === 'ask') {
            var searchInput = $('#id_title');
        } else {
            var searchInput = undefined;
            animateHashes();
        }

        if (searchInput) {
            searchInput.focus();
            putCursorAtEnd(searchInput);
        }

        var haveFullTextSearchTab = inArray(activeTab, ['questions', 'badges', 'ask']);
        var haveUserProfilePage = $('body').hasClass('user-profile-page');
        if ((haveUserProfilePage || haveFullTextSearchTab) && searchInput.length) {
            var search = new FullTextSearch();
            askbot['controllers'] = askbot['controllers'] || {};
            askbot['controllers']['fullTextSearch'] = search;
            search.setSearchUrl(askbot['data']['searchUrl']);
            if (activeTab === 'ask') {
                search.setAskButtonEnabled(false);
            }
            search.decorate(searchInput);
        } else if (activeTab === 'tags') {
            var search = new TagSearch();
            search.decorate(searchInput);
        }

        if (askbot['data']['userIsAdminOrMod']) {
            $('body').addClass('admin');
        }
        if (askbot['settings']['groupsEnabled']) {
            askbot['urls']['add_group'] = "{% url add_group %}";
            var group_dropdown = new GroupDropdown({{ group_list }});
            $('.dropdown').append(group_dropdown.getElement());
        }
        var userRep = $('#userToolsNav .reputation');
        if (userRep.length) {
            var showPermsTrigger = new ShowPermsTrigger();
            showPermsTrigger.decorate(userRep);
        }
    });
    if (askbot['data']['haveFlashNotifications']) {
        $('#validate_email_alert').click(function(){notify.close(true)})
        notify.show();
    }
    $('abbr.timeago').timeago();
    /*]]>*/
</script>
{% include "meta/custom_javascript.html" ignore missing %}
{# stuff below should not be compressed #}
{% if settings.ENABLE_MATHJAX %}
    {# we don't want to load mathjax just in case, only if it is really enabled #}
    <script type='text/javascript' src="{{settings.MATHJAX_BASE_URL}}/MathJax.js">
        MathJax.Hub.Config({
            extensions: ["tex2jax.js"],
            jax: ["input/TeX","output/HTML-CSS"],
            tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
        });
    </script>
{% endif %}
{% if settings.USE_CUSTOM_JS %}
<script 
    src="{% url "custom_js" %}?v={{ settings.MEDIA_RESOURCE_REVISION }}"
    type="text/javascript"
></script>
{% endif %}
{% if settings.GOOGLE_ANALYTICS_KEY %}
<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker('{{ settings.GOOGLE_ANALYTICS_KEY }}');
    pageTracker._trackPageview();
    } catch(err) {}
</script>
{% endif %}
